#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;


 // Definition for singly-linked list.
    struct ListNode {
    int val;
    ListNode *next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode *next) : val(x), next(next) {}
 };

class Solution {
public:
    ListNode* oddEvenList(ListNode* head) {
        if(head==nullptr){
            return nullptr;
        }
        ListNode* head1 = head;
        ListNode* head2;
        if(head->next!=nullptr){
            head2 = head->next;}
        else{
            return head;
        }
        ListNode* curr = head2->next;
        ListNode* curr1 = head1;
        ListNode* curr2 = head2;
        head1->next = nullptr;
        head2->next = nullptr;
        int i = 1;
        while(curr!=nullptr){
            if(i==1){
                curr1->next = curr;
                curr1 = curr1->next;
                curr = curr->next;
                curr1->next = nullptr;
                i=2;
            }
            else{
                curr2->next = curr;
                curr2 = curr2->next;
                curr = curr->next;
                curr2->next = nullptr;
                i=1;
            }
        }
        curr1->next = head2;
        return head;
    }
};

int main(){
    Solution S;
    ListNode* head = new ListNode(1);
    head->next = new ListNode(2);
    head->next->next = new ListNode(3);
    // head->next->next->next = new ListNode(5);
    // head->next->next->next->next = new ListNode(6);
    // head->next->next->next->next->next = new ListNode(4);
    // head->next->next->next->next->next->next = new ListNode(7);

    S.oddEvenList(head);
    return 0;
}